package file;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class FileTest
{
    @Test
    public void test()
    {
        List<FileFile> fileFiles = new ArrayList<>();
        fileFiles.add(new FileFile(1,"markerLib1",0,"root", "/",true,""));
        fileFiles.add(new FileFile(2,"markerLib2",0,"root", "/",true,""));
        fileFiles.add(new FileFile(3,"markerLib3",0,"root", "/",true,""));
        fileFiles.add(new FileFile(4,"markerLib4",1,"root", "/markerLib4",true,""));
        fileFiles.add(new FileFile(5,"markerLib5",1,"root", "/markerLib5",true,""));
        fileFiles.add(new FileFile(6,"markerLib6",4,"root", "/markerLib4/markerLib6",true,""));
        fileFiles.add(new FileFile(7,"markerLib7",4,"root", "/markerLib4/markerLib7",true,""));
        fileFiles.add(new FileFile(8,"markerLib8",6,"root", "/markerLib4/markerLib8/markerLib8.png",false,".png"));
        fileFiles.add(new FileFile(9,"markerLib9",7,"root", "/markerLib4/markerLib9/markerLib9.jpg",false,".jpg"));
        fileFiles.add(new FileFile(10,"markerLib10",8,"root", "/markerLib4/markerLib10/markerLib10.gpg",false,".gpg"));

        List<FileFile> q = new ArrayList<>();
        List<FileFile> m = new ArrayList<>();
        m.add(new FileFile(2, "markerLib1", 0, "root", "/", true, ""));
        recursiveQuery(q, fileFiles,m);

        for (FileFile fileFile : q)
        {
            System.out.println(fileFile.toString());
            System.out.println("=================");
        }
    }

    private void recursiveQuery(List<FileFile> alreadyQueryList,
                                List<FileFile> requiredQueryList,
                                List<FileFile> requiredQuery)
    {

        List<FileFile> newRequireDirQuery = new ArrayList<>();

        if (requiredQuery.size() == 0)
        {
            return;
        }
        for (FileFile fileFile : requiredQuery)
        {
            for (FileFile file : requiredQueryList)
            {
                if (fileFile.getFileId() == file.getParentId())
                {
                    alreadyQueryList.add(file);
                    newRequireDirQuery.add(file);
                }
            }
        }
        this.recursiveQuery(alreadyQueryList, requiredQueryList, newRequireDirQuery);
    }
}
